namespace SampleApp.Tests {
    using Microsoft.Services.TestTools.UITesting.Html;
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using SampleApp.Tests.Pages;

    [CodedUITest]
    public class ProductsTests : PageTest<Products> {
        
        [TestInitialize]
        public override void Initialize() {
            base.Initialize();
            TestedPage.EnsureAtLeastOneCategory();
        }

        [TestMethod]
        public void NewProductShowsUpInProductsList() {
            var name = Name();
            var productsList = TestedPage
                .NavigateToCreateProduct()
                .CreateNewProduct(name, Amount());

            bool isInList = productsList.ListContainsName(name);
            Assert.IsTrue(isInList, "The product wasn't present in the list");
        }

        [TestMethod]
        public void DetailsLinkNavigatesToDetailsPage() {
            var productName = TestedPage.ProductNameOnRow(0);
            var productDetails = TestedPage.ClickOnProductDetailsOnRow(0);

            bool containsName = productDetails.ContainsProductName(productName);
            Assert.IsTrue(containsName,"Product details page didn't contain the specified name <{0}>",productName);
        }
    }
}